type userS = string|null
import exec from '../db/connectMysql'


class user{
  private username:userS
  private password:userS
  private status:userS
  private realname:userS
  private id:number|null
  constructor(username:userS=null,password:userS=null,status:userS=null,realname:userS=null,id:number|null = null){
    this.username = username
    this.password = password
    this.status = status
    this.realname = realname
    this.id = id
  }
  async search(){
    let sql = `select * from user where username = ?`
    let arr:Array<string|null> = [this.username]
    return await exec(sql,arr)
  }
  async login(){
    let sql = `select * from user where username = ? and password = ?`
    let arr:Array<string|null> = [this.username,this.password]
    return await exec(sql,arr)
  }
  async register(){
    let sql = `insert into user(username,realname,password,status) values (?,?,?,?)`
    let arr:Array<string|null> = [this.username,this.realname,this.password,this.status]
    return await exec(sql,arr)
  }
}
export default user